package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.page.PageQuery2;
import com.ruoyi.common.core.page.ResultEntity;
import com.ruoyi.system.domain.TDeviceV2MaintenanceRecord;
import com.ruoyi.system.service.TDeviceV2MaintenanceRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liangjiuqing
 * @since 2024-09-27 10:14
 */
@Api(tags = "设备管理-设备维修记录接口")
@RestController
@RequestMapping("/deviceV2MaintenanceRecord")
public class TDeviceV2MaintenanceRecordController {
    @Autowired
    private TDeviceV2MaintenanceRecordService deviceV2MaintenanceRecordService;

    @ApiOperation("分页查询设备维修记录列表")
    @GetMapping("/listPageDeviceV2MaintenanceRecords")
    public ResultEntity<IPage<TDeviceV2MaintenanceRecord>> listPageDeviceV2MaintenanceRecords(DeviceV2MaintenanceRecordPageQuery deviceV2MaintenanceRecordPageQuery) {
        Page<TDeviceV2MaintenanceRecord> page = deviceV2MaintenanceRecordService.page(deviceV2MaintenanceRecordPageQuery.buildPage(),
                Wrappers.<TDeviceV2MaintenanceRecord>lambdaQuery()
                        .eq(deviceV2MaintenanceRecordPageQuery.getProjectId() != null, TDeviceV2MaintenanceRecord::getProjectId, deviceV2MaintenanceRecordPageQuery.getProjectId())
                        .orderByDesc(TDeviceV2MaintenanceRecord::getCreateTime));
        return ResultEntity.createSuccess(page);
    }

    @ApiOperation("新增或修改设备维修记录数据")
    @PostMapping("/saveOrUpdateDeviceV2MaintenanceRecord")
    public ResultEntity<Void> saveOrUpdateDeviceV2MaintenanceRecord(@Validated @RequestBody TDeviceV2MaintenanceRecord deviceV2MaintenanceRecord) {
        deviceV2MaintenanceRecordService.saveOrUpdate(deviceV2MaintenanceRecord);
        return ResultEntity.createSuccess(null);
    }

    @ApiOperation("批量删除设备维修记录数据")
    @GetMapping("/removeDeviceV2MaintenanceRecordByIds/{ids}")
    public ResultEntity<Void> removeDeviceV2MaintenanceRecordByIds(@ApiParam(value = "主键ID，逗号分隔", required = true) @PathVariable List<Long> ids) {
        deviceV2MaintenanceRecordService.removeByIds(ids);
        return ResultEntity.createSuccess(null);
    }

    @Data
    @EqualsAndHashCode(callSuper = true)
    static class DeviceV2MaintenanceRecordPageQuery extends PageQuery2 {
        @ApiModelProperty("项目id")
        private Long projectId;
    }

}
